<template>
	<view class="container">
		<view class="wifi-box">
			<image class="image" src="http://jy-nfc.oss-cn-hangzhou.aliyuncs.com/2024/12/26/d87b3f0285d849e29cdfb8b450f80f68.png" mode="widthFix"></image>
			<h2 style="text-align: center;">{{title}}</h2>
		</view>
	</view>
</template>

<script>
	import {
		setTimeout
	} from 'timers';
	import wifi from '@/utils/wifi'
	const app = getApp();
	export default {
		data() {
			return {
				title: '正在连接...',
				name: '',
				password: '',
				type: 0
			};
		},
		onLoad(e) {
			console.log(e);
			this.name = e.name || ''
			this.password = e.password || ''
			this.type = e.type || 0
			setTimeout(() => {
				this.cStartWifi()
			}, 500)
		},

		methods: {
			cStartWifi() {
				const checkPlatform = wifi.checkPlatform()
				checkPlatform.then((res) => {
					console.log(res);
					var maunal = false
					if (res.platform == "android" && res.system < 10 && this.type == 2) maunal = true;
					wifi.initWifi().then(() => {
						console.log('initWifi');
						wifi.connectWifi({
							SSID: this.name,
							password: this.password,
						}, maunal).then(() => {
							console.log('connectWifi');
							this.title = 'WiFi连接成功'
						}).catch(() => {
							console.log('connectWifierr', err);
							this.title = 'WiFi连接失败'
						})
					}).catch((err) => {
						console.log('initWifierr', err);
						this.title = 'WiFi连接失败'
					})
				}).catch((err) => {
					this.title = '获取设备信息失败'
				})


				// 	wx.startWifi({
				// 		success: (success) => {
				// 			console.log("success", success)
				// 			wx.connectWifi({
				// 				SSID: 'juyue',
				// 				password: 'juyue123', // 这里需要用户输入真实的WiFi密码
				// 				// maunal: true, //跳转到系统设置页进行连接
				// 				success: (res) => {
				// 					console.log("WiFi连接成功", res);
				// 					// 连接成功后的处理逻辑
				// 					this.title = 'WiFi连接成功'
				// 				},
				// 				fail: (err) => {
				// 					console.log("WiFi连接失败", err);
				// 					// 连接失败后的处理逻辑
				// 				}
				// 			});
				// 		},
				// 		fail: (err) => {
				// 			console.log("WiFi初始化失败", err);
				// 		}
				// 	})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.container {
		overflow: hidden;
		min-height: 100vh;
		width: 100vw;
		padding: 40rpx;
		padding-top: 226rpx;
		// padding-bottom: calc(96rpx + 32rpx + 22rpx);
		box-sizing: border-box;
		background: radial-gradient(128% 128% at 95% 0%, #D7CEFF 0%, #BBE1FF 62%, #FFFFFF 95%);

		.wifi-box {
			display: flex;
			flex-wrap: wrap;
			justify-content: center;

			.image {
				width: 80vw;
				margin-bottom: 40rpx;
			}
		}
	}
</style>